package com.ruoyi.web.controller.test;

import cn.hutool.core.lang.Console;
import cn.hutool.json.JSONUtil;
import com.aliyun.dyvmsapi20170525.models.QueryCallDetailByCallIdResponse;
import com.aliyun.dyvmsapi20170525.models.SingleCallByTtsResponse;
import com.aliyun.dyvmsapi20170525.models.SingleCallByVoiceResponse;
import com.aliyun.tea.TeaException;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Sample {
    /**
     * <b>description</b> :
     * <p>使用凭据初始化账号Client</p>
     *
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dyvmsapi20170525.Client createClient() throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填，System.getenv()表示从环境变量中获取AccessKey ID
                .setAccessKeyId("LTAI5tHrNWjppdT9hj6uL4Vd")
                // 必填，System.getenv()表示从环境变量中获取AccessKey Secret
                .setAccessKeySecret("YLUCJv4rYqBAFvNE6GAd76sYFAfuTX");
        config.endpoint = "dyvmsapi.aliyuncs.com";
        return new com.aliyun.dyvmsapi20170525.Client(config);
    }

    public static void main(String[] args_) throws Exception {
 /*       com.aliyun.dyvmsapi20170525.Client client = Sample.createClient();
        com.aliyun.dyvmsapi20170525.models.SingleCallByTtsRequest singleCallByTtsRequest = new com.aliyun.dyvmsapi20170525.models.SingleCallByTtsRequest();
        singleCallByTtsRequest.setCalledShowNumber("");
        singleCallByTtsRequest.setCalledNumber("151712411232");
        singleCallByTtsRequest.setTtsCode("TTS_322445054");
        Map<String, String> map = new HashMap<>();
        map.put("projectName", "龙阳湖项目");
        map.put("deviceName", "塔机一号");
        singleCallByTtsRequest.setTtsParam(JSONUtil.toJsonStr(map));
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            SingleCallByTtsResponse singleCallByTtsResponse = client.singleCallByTtsWithOptions(singleCallByTtsRequest, runtime);
            Console.log("阿里云返回{}", JSONUtil.toJsonStr(singleCallByTtsResponse));
            if (!"200".equals(singleCallByTtsResponse.getStatusCode().toString()) || !singleCallByTtsResponse.body.code.equals("OK")) {

            }
            String callId = singleCallByTtsResponse.getBody().callId;
           // dealResult(callId);
        } catch (TeaException error) {
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }*/
        dealResult(null);
    }

    public static void dealResult(String callId) throws Exception {
        com.aliyun.dyvmsapi20170525.Client client = Sample.createClient();
        com.aliyun.dyvmsapi20170525.models.QueryCallDetailByCallIdRequest queryCallDetailByCallIdRequest = new com.aliyun.dyvmsapi20170525.models.QueryCallDetailByCallIdRequest();
        queryCallDetailByCallIdRequest.setCallId("151808667132^138551647132");
        queryCallDetailByCallIdRequest.setProdId(11000000300006l);
        queryCallDetailByCallIdRequest.setQueryDate(System.currentTimeMillis());
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            QueryCallDetailByCallIdResponse queryCallDetailByCallIdResponse = client.queryCallDetailByCallIdWithOptions(queryCallDetailByCallIdRequest, runtime);
            Console.log("阿里云返回{}", JSONUtil.toJsonStr(queryCallDetailByCallIdResponse));
            Object state = JSONUtil.parseObj(queryCallDetailByCallIdResponse.getBody().getData()).get("state");
            System.out.println(state);
        } catch (TeaException error) {
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}
